package com.xx.pinball.framwork;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xx
 *
 * @param <T>
 */
public abstract class Pool<T> {
    private List<T> items = new ArrayList<T>();
    
    protected abstract T newItem();
    
    public T obtain() {
        if(items.size() == 0) return newItem();
        return items.remove(0);
    }
    
    public void free(T item) {
        items.add(item);
    }
}
